package com.example.azheng.okhttpdemo.utils;

import android.content.Context;
import android.support.annotation.NonNull;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class GlideUtils extends AppGlideModule {

    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {

        //        设置手机默认推荐缓存大小。
        // MemorySizeCalculator类通过考虑设备给定的可用内存和屏幕大小想出合理的默认大小.
        MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context)
                .setMemoryCacheScreens(4)
                .build();
        builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize()));
        //默认的Glide硬盘缓存大小为250
        int diskCacheSize = 1024 * 1024 * 250;
        builder.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, diskCacheSize));

    }

}